require('../../assets/css/index.js')
require('../../assets/fonts/font/iconfont.css')
require('../../assets/lib/swiper/swiper-bundle.css')
let Swiper = require('../../assets/lib/swiper/swiper-bundle.js')
require('../../utils/local.js')
let https = require('../../utils/https.js')

// 引入公共js
let dom = require('../../utils/dom.js')
const local = require('../../utils/local.js')
//引入当前页面的less文件
require('./mine.less')
// 当前页面js
dom.isLogin()

dom.ready(function () {
    dom.bMenu('mine')
    // 获取当前用户最新信息
    function getUserInfo() {
        https.get('/api/user/info', {}, function (res) {
            if (res.errno == 0) {
                local.set('userInfo', res.data)
                Rander()
            }
        })
    }
    getUserInfo();
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

        // 如果需要前进后退按钮
        // navigation: {
        //   nextEl: '.swiper-button-next',
        //   prevEl: '.swiper-button-prev',
        // },

        // 如果需要滚动条
        // scrollbar: {
        //   el: '.swiper-scrollbar',
        // },
    })
    function Rander() {

        let userData = local.get('userInfo');
        console.log(userData);
        // 把数据渲染到对于位置
        dom.getEle('#pic').src = https.hostUrl + userData.imgUrl;
        dom.getEle('#userName').innerHTML = userData.nickName;
        dom.getEle('#sign').innerHTML = userData.sign ? userData.sign : '人生若只如初见';
    }
    Rander()
    // 上传背景图片
    dom.getEle("#icon-pifu").addEventListener("change", function () {
        let pic = this.files[0];
        // console.log(pic);
        let fd = new FormData();
        fd.append('file', pic);
        https.post('/api/shared/uploadPortrait1', fd, function (res) {
            console.log(res);
            if (res.errno == 0) {
                dom.getEle("body").style.background = `url(${https.hostUrl + res.data.url})`;
            }
        })
    })
})
